//
//  UIBarButtonItem+extension.m
//  oc-wei
//
//  Created by xue-iOS-work on 16/8/30.
//  Copyright © 2016年 xue. All rights reserved.
//

#import "UIBarButtonItem+extension.h"

@implementation UIBarButtonItem (extension)
+ (instancetype)barButtonWithTitle:(NSString *)title image:(NSString *)images style:(UIBarButtonItemStyle *)style target:(id)target action:(SEL)action {
    UIButton *btn = [[UIButton alloc] init];
    // 设置图片
    NSString *str1 = [NSString stringWithFormat:@"%@", images];
    [btn setImage:[UIImage imageNamed:str1] forState:UIControlStateNormal];
    NSString *str2 = [NSString stringWithFormat:@"%@_highlighted", images];
    [btn setImage:[UIImage imageNamed:str2] forState:UIControlStateHighlighted];
    // 设置文字
//    btn.titleLabel.text = title;
    [btn setTitle:title forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:14];
    [btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor orangeColor] forState:UIControlStateHighlighted];
    [btn sizeToFit];
    // 监听事件
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *b = [[UIBarButtonItem alloc] initWithCustomView:btn];
    return b;
}
@end
